<?php

namespace app\canteen\admin;
use app\common\builder\ZBuilder;
use app\common\model\StConfig as StConfigModel;
class StConfig extends Base
{

    public function index($id=0){

//        dump($id);
        if ($this->request->isPost()) {
            $data = $this->request->post();
            if ($id==0){
                $boolf = StConfigModel::create($data);
            } else{
                $boolf = StConfigModel::update($data);
            }

            if ($boolf) {
                $this->success('更新成功啦!');
            } else {
                $this->error('更新失败哦!');
            }
        }

        // 模块配置值
        $info  = StConfigModel::where('comid', COMID)->find();
        $id = 0;
        if ($info['id']) $id = $info['id'];
        return ZBuilder::make('form')
            ->addGroup([
                '系统设置' =>[
                    ['hidden', 'id', $id],
                    ['hidden', 'comid', COMID],
                    ['text', 'title', '公司名称', '请输入公司名称'],

                    ['Timerange', 'stare_time,end_time', '用餐时间范围', '', '', ''],

                ],
                '农场设置' =>[
                    ['text', 'farm_notice', '农场公告', '请输入农告']
                ]

                ])
            //->addTimerange('stare_time,end_time', '日期范围', '', '', '', 'data-start-date=2017-05-05')
            ->setFormData($info)
            ->layout(['stare_time' => 7,'end_time'=>6,'title' => 7,'cost_free'=>6,'cost' => 6,
                'over_day'=>6,'overtime'=>6,'stock' => 6,'start_price'=>6,'e_rate'=>6])
            ->fetch();

    }

}